											<!-- 护士输入分娩量 -->
<include file="common:header" />

<div class="page__hd">
    <h1 class="page__title">医院分娩量</h1>
    <p class="page__desc">请输入对应日期的分娩量和销售量</p>
</div>

<!-- 主体内容 -->
<div class="weui-tab__panel">

	<form id="deliveryForm">
		<div class="weui-cells">
			<div class="weui-cell">
	            <div class="weui-cell__hd"><label for="" class="weui-label">分娩日期</label></div>
	            <div class="weui-cell__bd">
	                <input class="weui-input" id="showDatePicker" name="del_date" placeholder="请选择日期，仅上月和今月日期">
	            </div>
	        </div>
			<div class="weui-cell">
			    <div class="weui-cell__hd"><label for="" class="weui-label">分娩数量：</label></div>
			    <div class="weui-cell__bd">
					<input class="weui-input" name="del_num" type="number" pattern="[0-9]*" value="" placeholder="请输入分娩数量">
			    </div>
			</div>
			<div class="weui-cell">
			    <div class="weui-cell__hd"><label for="" class="weui-label">销售数量：</label></div>
			    <div class="weui-cell__bd">
					<input class="weui-input" name="sale_num" type="number" pattern="[0-9]*" value="" placeholder="请输入销售数量">
			    </div>
			</div>
		</div>

		<div class="weui-cells__title">温馨提示：分娩日期对应的分娩数量提交后，不可再次修改!</div>

		<!-- 立即提交 -->
		<div class="weui-btn-area">
		    <a href="javascript:;" class="weui-btn weui-btn_primary weui-btn_disabled comfirm">提交</a>
		</div>
		<!-- 立即提交 -->
	</form>

	<notempty name="born_num">

		<div class="weui-cells__title">
			销售量/分娩量 &nbsp;&nbsp;&nbsp; 当月数据：{$sale_num}/{$born_num}
		</div>

		<!-- 九宫格 -->
		<div class="weui-grids">
			<foreach name="born_data" item="vo" >
				<empty name="vo.num">
			        <a href="javascript:;" class="weui-grid">
			            <p class="weui-grid__label"> 0 个</p>
			            <div class="weui-grid__icon">
			            	<i class="weui-icon-cancel"></i>
			            </div>
			            <p class="weui-grid__label">{$vo.date} </p>
			        </a>
		        <else/>
		        	<a href="javascript:;" class="weui-grid">
			            <p class="weui-grid__label">{$vo.snum} / {$vo.num} 个</p>
			            <div class="weui-grid__icon">
			            	<i class="weui-icon-success-no-circle"></i>
			            </div>
			            <p class="weui-grid__label">{$vo.date} </p>
			        </a>
				</empty>
			</foreach>
	    </div>
		<!-- 九宫格 -->

	</notempty>

</div>
<!-- 主体内容 -->

<script type="text/javascript">
$(document).ready(function(){
	$('title').html('分娩量');

	//H5禁止手机自带键盘弹出
	$("#showDatePicker").focus(function(){
        document.activeElement.blur();
    });

	//判断一下,是否登录？
	var loginFlag = $.cookie('login');
	if (!loginFlag) {
		//未登录
		login_func();
	}else{
		// 已登录
		if ($.cookie('hospitalName')) {
			//登录之后 操作的医院名称
			var hospitalName = $.cookie('hospitalName');
			$('.page__title').html(hospitalName+" 医院分娩量");
			$('.comfirm').removeClass('weui-btn_disabled');
		}
	}

	//登录方法
	function login_func(){
		$.login({
			//如果参数过多，建议通过 object 方式传入
		  	title: '登录',
		  	text: '请输入用户名和密码',
		  	username: 'nurse',  // 默认用户名
		  	password: '',  // 默认密码
		  	onOK: function (username, password) {
		    	//点击确认
		    	login(username,password);
		  	},
		  	onCancel: function () {
		    	//点击取消
		    	layerCallBackTips('请登录后，再进行操作!');
		    	login_func();
		  	}
		});
	}

	/**
	 * [login 提交登录]
	 * @author xiezy
	 * @date   2018-05-24
	 * @return {[type]}   [description]
	 */
	function login(u,p){
		var postData = {
			username:u,
			password:p
		};
		$.post("{:U(MODULE_NAME.'/'.CONTROLLER_NAME.'/login')}",postData,function(data){
			$.toast(data.info , function() {
				if (data.status) {
					//提交按钮重新启用
					window.location.href = data.url;
				}else{
					//登录失败，重新调用登录窗口，进行登录。
					login_func();
				}
	        });
		});
	}

	// 提交成功--医院的分娩量
	$('.comfirm').on('click', function(){
		if ( $('input[name=del_date]').val()=='' ) {
			layerCallBackTips('请选择分娩日期');
			return false;
		}else if( $('input[name=del_num]').val()=='' ){ /*備註必填*/
			layerCallBackTips('请填写分娩数量');
			return false;
		}else if( $('input[name=sale_num]').val()=='' ){ /*備註必填*/
			layerCallBackTips('请填写销售数量');
			return false;
		}
		$.confirm("确认分娩数量,填写无误？","分娩量", function() {
			//点击确认后的回调函数
			$.post("{:U(MODULE_NAME.'/'.CONTROLLER_NAME.'/saveDeliveryOrder')}",$('#deliveryForm').serialize(),function(data){
				$.toast(data.info , function() {
		        	window.location.href = data.url;
		        });
			});
	  	});

    });

	//酷炫时间picker
	$('#showDatePicker').on('click', function () {
        weui.datePicker({
            start: 2018,
            end: new Date().getFullYear()+1,
            defaultValue: [new Date().getFullYear(), (new Date().getMonth() + 1), new Date().getDate()],
            onConfirm: function (result) {
            	var res = result.join("-");
                $("#showDatePicker").val(res);
            }
        });
    });
});
</script>
